/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package it.polimi.leo.jg;

import it.polimi.leo.mw.IMiddleWareGroup;
import it.polimi.leo.mw.IMiddleWareNode;
import it.polimi.leo.mw.JoinGroupException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jgroups.JChannel;

/**
 *
 * @author Lev
 */
public class JGGroup implements IMiddleWareGroup {
    String jGroupsClusterName;

    public JGGroup(String clusterName) {
        jGroupsClusterName = clusterName;
    }

    public String getID() {
        return jGroupsClusterName;
    }

    public List<IMiddleWareNode> getListners() {
        IMiddleWareNode n = null;
        try {
            return (n = new JGNode(new JChannel()).joinGroup(this))
                    .getGroupListners();
        } catch (Exception ex) {
            Logger.getLogger(JGGroup.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                n.leaveGroup();
            } catch (JoinGroupException ex) {
                Logger.getLogger(JGGroup.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return null;
    }

}
